package com.shunan.miaosha.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shunan.miaosha.beans.MiaoshaGoods;
import com.shunan.miaosha.dao.GoodsDao;
import com.shunan.miaosha.vo.GoodsVo;

@Service
public class GoodsService {
	
	@Autowired
	GoodsDao goodsDao;
	
	public List<GoodsVo> listGoodsVo(){
		return goodsDao.listGoodsVo();
	}

	public GoodsVo getGoodsVoByGoodsId(int goodsId) {
		return goodsDao.getGoodsVoByGoodsId(goodsId);
	}
	/**
	 * 是否减 数量成功，减库存的前提是 库存大于0，并且存在这个货物。
	 * @param goods
	 * @return
	 */
	public boolean reduceStock(GoodsVo goods) {
		MiaoshaGoods g = new MiaoshaGoods();
		g.setGoodsId(goods.getId());
		int i=goodsDao.reduceStock(g);
		return i!=0;
	}
	
	
	
}
